<?php
/**
 * 图书数据模型
 * 
 * @author sandy
 *
 */
class bookModel extends Model {
	
	/**
	 * 获取指定分页图书信息
	 * 
	 * @param array $page_info 分页信息
	 */
	public function get_top_book($category_id = 0, $order = "addtime DESC", $offset = 10){
		
		$category_id = intval($category_id);
		$offset = intval($offset);
		
		if ($category_id > 0) {
			$sql = "SELECT * FROM #__books 
					WHERE category_id = $category_id 
					ORDER BY $order";
		} else {
			$sql = "SELECT * FROM #__books 
					ORDER BY $order";
		}
		
		$this->db->set_query($sql,0,$offset);
		
		return $this->db->get_all();
	}
	
	/**
	 * 获取指定图书信息
	 * @param int $book_id
	 */
	public function get_book_info($book_id){
	
		$book_id = intval($book_id);
		if (!$book_id){
			return false;
		}
	
		$sql = "SELECT b.*,a.author_name,c.category
		FROM #__books b
		LEFT JOIN #__author a
		ON b.author_id = a.author_id
		LEFT JOIN #__category c
		ON b.category_id = c.category_id
		WHERE b.book_id = $book_id";
	
		$this->db->set_query($sql);
	
		return $this->db->get_row();
	}
}


